package cn.dubito.o2o.web.admin;

import cn.dubito.o2o.domian.entity.Area;
import cn.dubito.o2o.service.AreaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liliang
 * @description:
 * @date 2018/4/17.
 */
@Controller
@RequestMapping("/admin")
public class AreaController {

    Logger logger = LoggerFactory.getLogger(AreaController.class);

    @Autowired
    private AreaService areaService;

    @RequestMapping(value = "/areaList", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> getAreaList() {
        logger.info("========start==========");
        long startTime = System.currentTimeMillis();
        Map<String, Object> model = new HashMap<>(16);
        List<Area> areaList = new ArrayList<>();
        try {
            areaList = areaService.queryAreaList();
            model.put("row", areaList);
            model.put("total", areaList.size());
        } catch (Exception e) {
            e.printStackTrace();
            model.put("success", false);
            model.put("errMsg", e.toString());
        }
        logger.error("test error");
        long endTime = System.currentTimeMillis();
        logger.debug("costTime:{}",endTime - startTime);
        logger.info("========end==========");
        return model;
    }


    @RequestMapping("/get")
    @ResponseBody
    public List<Area> get() {
        return areaService.queryAreaList();
    }

}
